import axios, { AxiosRequestConfig, AxiosResponse } from 'axios'

const javaInstance = createInstance('http://localhost:28082/api')
const goInstance = createInstance('http://localhost:28082/goapi')

export function audit(config: AxiosRequestConfig<any>, status = 200) {
  return new Promise<{
    request1: AxiosResponse<any>,
    request2: AxiosResponse<any>
  }>(async (resolve) => {
    const req1 = await javaInstance.request(config)
    const req2 = await goInstance.request(config)

    expect(req1.status).toBe(status)
    expect(req2.status).toEqual(req2.status)

    expect(req1.data.data).toEqual(req2.data.data)

    resolve({
      request1: req1,
      request2: req2
    })
  })
}

export function createInstance(baseURL: string) {
  return axios.create({
    baseURL,
    headers: {
      'Content-Type': 'application/json'
    }
  })
}
